package com.tz.test.sender;

import com.sunducation.rabbitmq.api.IReceiver;
import com.sunducation.rabbitmq.api.RabbitUtilAbstract;
import com.sunducation.rabbitmq.api.enums.RabbitTypeEnum;
import com.sunducation.rabbitmq.api.model.RegistInfo;
import com.tz.test.handle.MessageSender;
import com.tz.test.handle.MqMessageHandle;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author zhangky
 * @since 2020/5/7
 */
@Service("childMessageSend")
public class ChildMessageSend extends RabbitUtilAbstract implements MessageSender {

    @Value("${seac.systemName}")
    String systemName ;
    @Value("${wts.api.queue.cutPic}")
    String queueName;
    @Value("${wts.api.exchange.cutPic}")
    String exchangeName;
    @Value("${wts.api.exchangeType}")
    String exchangeType;

    private void makeRegisterInfo() {
        if(null == registInfo)
            registInfo = new RegistInfo();
        registInfo.setQueueName("queue.test");
        registInfo.setExchangeName(exchangeName);
        registInfo.setExchangeType(RabbitTypeEnum.getEnumeByName(exchangeType).getId());
        registInfo.setSystemName(systemName);
    }
    public void sendMsg(Object content) throws Exception {
        makeRegisterInfo();
        rabbitMQService.setRegistInfo(registInfo);
        rabbitMQService.send(content);
    }

    @Override
    public IReceiver getReceiver(){
        return new MqMessageHandle();
    }

    @Override
    public RegistInfo getRegisteInfo(){
        makeRegisterInfo();
        return registInfo;
    }

    @Override
    public void sendMessage(Object o) {
        try {
            this.sendMsg(o);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
